package com.youths.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.youths.dao.ExpertInfoMapper;
import com.youths.dao.LabelConsumerMapper;
import com.youths.domain.ExpertInfo;
import com.youths.service.ExpertInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExpertInfoServiceImpl implements ExpertInfoService {

    @Autowired(required = false)
    ExpertInfoMapper expertInfoMapper;

    @Autowired(required = false)
    LabelConsumerMapper labelConsumerMapper;

    @Override
    public PageInfo getExpertInfoList(Integer pageNum, Integer expertId, Integer consumerId, String name, String company, String title) {
        PageHelper.startPage(pageNum,10);
        List<ExpertInfo> experts = expertInfoMapper.getList(expertId,consumerId,name,company,title);
        PageInfo<ExpertInfo> expertInfoPageInfo = new PageInfo<>(experts);
        return expertInfoPageInfo;
    }

    @Override
    public String updateExpertInfo(Integer expertId, Integer consumerId, String name, String company, String title, Integer state) {
        Integer result = expertInfoMapper.updateExpertInfo(expertId,name,company,title,state);
        if(result == 1){
            result = labelConsumerMapper.updateConsumer(consumerId,name);
            if(result == 1){
                return "success";
            }
        }
        return "fail";
    }

}
